package org.mspring.mlog.web.module.admin;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.mspring.mlog.Application;
import org.mspring.mlog.entity.CodeBook;
import org.mspring.mlog.entity.Post;
import org.mspring.mlog.entity.SysUser;
import org.mspring.mlog.entity.ToDo;
import org.mspring.mlog.service.CodeBookService;
import org.mspring.mlog.service.ToDoService;
import org.mspring.mlog.service.UserService;
import org.mspring.platform.web.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Widget
@RequestMapping("/admin")
@Controller("todoWidgetAct")
public class ToDoWidget {

	private static final Logger log = Logger.getLogger(ToDoWidget.class);

	private ToDoService todoService;
	
	private CodeBookService codeBookService;
	
	private UserService userService;

	@Autowired
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	@Autowired
	public void setTodoService(ToDoService todoService) {
		this.todoService = todoService;
	}

	@Autowired
	public void setCodeBookService(CodeBookService codeBookService) {
		this.codeBookService = codeBookService;
	}

	@RequestMapping("/todo")
	public String about(HttpServletRequest request,
			HttpServletResponse response, Model model) {
		Application app = Application.getInstance();
		model.addAttribute("app", app);
		return "/admin/todo/createToDo";
	}

	@RequestMapping("/todo/doCreate")
	public String createPostView(@ModelAttribute ToDo toDo,
			HttpServletRequest request, HttpServletResponse response,
			Model model) {
		List<CodeBook> codeBook = codeBookService.getCodeBookByType("LEVEL");
		model.addAttribute("codeBook", codeBook);
		List<SysUser> user = userService.getAllUser();
		model.addAttribute("user", user);
        // 是否开启公开表示
        Map<String, String> commentStatus = new HashMap<String, String>();
        commentStatus.put(Post.CommentStatus.OPEN, "开启");
        commentStatus.put(Post.CommentStatus.CLOSE, "关闭");
        model.addAttribute("commentStatus", commentStatus);
		return "/admin/todo/createToDo";
	}
}
